clear
% clc
close all

% Folder for static data
folderName = 'staticTestData/';

% Specific thrust data file
thrustFilename = 'demoStaticTest.txt';


% Load the data and initial conditions
tic
data = loadPrelimConditions([folderName thrustFilename], 1);
loadtime = toc;

x0 = [0,0,0,0,0,0,data.initWMass]';

options = odeset('RelTol',1e-9);
tic
[t,x] = ode45(@rocketODE,[0,6],x0,options,data);
% [t,x] = euler(@rocketODE,[0:.001:4],x0,options,data);
simTime = toc;
avgdt = mean(diff(t));
fprintf('The Average time step = %2.1e s\n',avgdt)

frontOffset = find(0.1*t(end) > t,1,'last');
[dum,ind] = min(abs(x(frontOffset:end,2)));
ind = ind +frontOffset;

maxdist = sqrt(x(ind,1)^2+x(ind,3)^2);
maxdistft = maxdist*3.28;
maxheight = max(x(:,2));
maxHft = maxheight*3.28;


figure
plot(x(:,1),x(:,2))
xlabel('xpos')
ylabel('ypos')
title('rocket trajectory')
grid on
axis([0,maxdist,0,1.2*max(x(:,2))])

% hold all
% plot(x(:,1),x(:,7))



fprintf('The max distance is %3.1f ft or %3.1f m\n',maxdistft,maxdist)
fprintf('The max height is %3.1f ft or %3.1f m\n',maxHft,maxheight)
fprintf('The data load time is %3.1f s while the simulation took %3.1f s\n',loadtime,simTime)
